'use strict';
//////////////////////////////////////////////////////////////////////////////
// 元素拖动功能
// =====================
// liuyp 2019年2月13日19: 00: 02
//////////////////////////////////////////////////////////////////////////////
function draggable($document) {
    var zindex = 100
    return function(scope, element, attr) {
        var startX = 0, startY = 0;
        element.css({ position: 'relative', cursor: 'move' });
        element.on('mousedown', function(event) {
            event.preventDefault();
            startX = event.pageX - $(element).position().left;
            startY = event.pageY - $(element).position().top;
            $document.on('mousemove', mousemove);
            $document.on('mouseup', mouseup);
            element.css("z-index",++zindex);
        });
        function mousemove(event) {
            var y = event.pageY - startY;
            var x = event.pageX - startX;
            element.css({ top: y + 'px', left:  x + 'px' });
        }
        function mouseup() {
            $document.off('mousemove', mousemove);
            $document.off('mouseup', mouseup);
        }
    };
}
exports = module.exports = draggable;